/**
 * 文档作者: wj
 * 创建时间：2018年05月05日
 * 修改时间：2018年05月05日
 * 描述信息：积分页面
 */

import React, {Component} from 'react';
import './integral.scss';
import TimeList from '../components/time-list/time-list';
// import data from '../components/time-list/time-list.model';
import userModel from '../api/user.model';
import util from '../../util/util';

class Integral extends Component {
    constructor(props) {
        super(props);
        this.state = {
            list: void 0,
            jifenGroup: void 0
        }
    }
    componentWillMount() {
        const obj = {
            uid: userModel.svcRegWithWx.uid,
            apptoken: userModel.svcRegWithWx.apptoken
        }
        window.$http.post(`${window.$apiUrl}/svcBusiUser/svcLoadSelfJifenList`, obj).then((res) => {
            this.setState({
                list: res.data.info.data
            });
        })
        window.$http.post(`${window.$apiUrl}/svcBusiUser/svcLoadSelfJifenGroupBy`, obj).then((res) => {
            this.setState({
                jifenGroup: res.data.info.data
            })
        })
    }
    render() {
        return <div className='integral-page page'>
                    <p className='gray'>亲爱的华亭哈密瓜会员<span>{userModel.svcRegWithWx.uinfo.wx_nickname}</span>，您的积分情况如下：</p>
                    <div className='integral'>
                        <div className='left'>
                            <p className='gray'>可用</p>
                            <h1>{(this.state.jifenGroup && this.state.jifenGroup[0].jifen_sum) || 0}</h1>
                        </div>
                        <div className='right'>
                            <p className='gray'>已兑换</p>
                            <h1>{(this.state.jifenGroup && this.state.jifenGroup[1].jifen_sum) || 0}</h1>
                        </div>
                    </div>
                    <p className='gray'>积分使用明细如下:</p>
                    {this.state.list && this.state.list.length > 0 && <TimeList data={this.state.list}></TimeList>}
                </div>
    }
    componentDidMount() {
        util.setTitle('积分');
      }
}

export default Integral;